package View;

import com.nokia.mid.ui.orientation.Orientation;
import com.sun.lwuit.*;
import com.sun.lwuit.animations.CommonTransitions;
import testmenu.MainMidlet;

public class SplashScreen extends View {

    private Image image;

    public SplashScreen(MainMidlet midlet, Image image) {
        super(midlet);
//        String k = midlet.setThemeRecordname();
//        try{
//         midlet.loadTheme(k);
//        } catch(Exception e){
//            e.printStackTrace();
//        }
        this.image = image;
        hideDefaultTitle();
        setTransitionOutAnimator(CommonTransitions.createSlide(
                CommonTransitions.SLIDE_VERTICAL, true, 2000));
        final Slider sl1 = new Slider();
        sl1.setRenderPercentageOnTop(true);
//        sl1.setInfinite(true);
        addComponent(sl1);
        new Thread() {
            private int val = 0;
            public void run() {
                try {
                    while (val <= 100) {
                        sleep(10);
                        sl1.setProgress(val);
                        val++;
                    }
                } catch (InterruptedException ex) {
                }
            }
        }.start();
    }

    public void paint(Graphics g) {
        g.setColor(0xffffff);
        g.fillRect(0, 0, getWidth(), getHeight());
        int x = getWidth() / 2 - image.getWidth() / 2;
        int y = getHeight() / 2 - image.getHeight() / 2;
        g.drawImage(image, x, y);
    }

    private void hideDefaultTitle() {
        getTitleArea().getStyle().setPadding(0, 0, 0, 0);
        getTitleArea().setVisible(false);
        getTitleComponent().setVisible(false);
    }
}
